﻿namespace ProxyServer.Endpoints;

public static class Extensions
{
    public static IEndpointConventionBuilder MapEndpoints(this IEndpointRouteBuilder endpoints)
    {
        var v1apis = endpoints.MapGroup("/api/v1");

        v1apis.MapGet("/services", ServiceEndpoints.ListAllServices);
        v1apis.MapPost("/service", ServiceEndpoints.SaveService);
        v1apis.MapDelete("/service/{id:guid}", ServiceEndpoints.DeleteService);
        v1apis.MapPost("/publish", BaseEndpoints.Publish);

        v1apis.MapGet("/current/routes", BaseEndpoints.GetCurrentRoutes);
        v1apis.MapGet("/current/clusters", BaseEndpoints.GetCurrentClusters);
        v1apis.MapGet("/current/route/{id}", BaseEndpoints.GetRoute);
        v1apis.MapGet("/current/cluster/{id}", BaseEndpoints.GetCluster);

        v1apis.MapGet("/snapshot/list", SnapshotEndpoints.ListSnapshots);
        v1apis.MapPost("/snapshot/apply/{id:guid}", SnapshotEndpoints.Apply);
        v1apis.MapGet("/snapshot/{id:guid}", SnapshotEndpoints.GetSnapshotDetails);

        var events = v1apis.MapGroup("/events").WithTags("Services");
        events.MapPost("/checkaccount", EventEndpoints.CheckAccount);
        events.MapPost("/checkservice/{id:guid}", EventEndpoints.CheckService);

        v1apis.MapCertsEndpoints();

        return v1apis;
    }
}
